#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more 
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership. 
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with 
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion


using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;


namespace IPSim.GUI.Devices
{
    public class ComputerDevice : PictureDevice, IConsoleAccess
    {
        #region Members

        private DeviceConsole deviceConsole = null;

        #endregion

        #region Methods

        public ComputerDevice(int top, int left) : base(top,left,Properties.Resources.computer64)
        {
            InitConnectors();            
        }
        
        protected void InitConnectors()
        {
            connectors.Add(new ConnectorDevice(this));
            UpdateConnectorsPosition();
        }

        internal override void UpdateConnectorsPosition()
        {
            Point loc;
            ConnectorDevice connector;
            connectorSize = 17;

            //Bottom
            loc = new Point(this.location.X + this.size.Width / 2,
                this.location.Y + this.size.Height / 2);
            connector = (ConnectorDevice)connectors[0];
            connector.Location = new Point(loc.X - connectorSize, loc.Y - connectorSize);
            connector.Size = new Size(connectorSize * 2, connectorSize * 2);

        }

        #region IConsoleAccess Members

        public void AttachConsole(DeviceConsole console)
        {
            deviceConsole = console;
            deviceConsole.SetPrompt("Computer:# ");
        }

        public void DeattachConsole()
        {
            deviceConsole = null;
        }

        public void IssueCommand(string command)
        {
            //process command
            if (deviceConsole != null)
                deviceConsole.WriteText("[Computer] - Command received: " + command);
        }

        public string GetDeviceProlog()
        {
            return "Academic IP Simulator" + Environment.NewLine + "by Jovan Brakus, aug 2008" + Environment.NewLine + "-----------------------------" + Environment.NewLine + "Computer Device Console v0.0.1" + Environment.NewLine + Environment.NewLine;
        }

        #endregion

        #endregion

        #region Properties
        [Category("Ethernet Interface")]
        [Browsable(true)]
        [Description("Ethernet Interface - IP Address")]
        public IPSim.Data.IPAddress IPAddress4
        {
            get
            {
                return new IPSim.Data.IPAddress(123);
            }
        }
        [Category("Ethernet Interface")]
        [Browsable(true)]
        [Description("Ethernet Interface - SubNet mask")]
        public IPSim.Data.IPAddress SubnetMask4
        {
            get
            {
                return new IPSim.Data.IPAddress(345466354);
            }
        }

        [Category("Power")]
        [Browsable(true)]
        [Description("Device Power - ON/OFF")]
        public bool PoweredOn
        {
            get
            {
                return false;
            }
        }

        #endregion

        #region Events


        #endregion

    }
}
